

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=&#34;auto&#34;>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/2.jpg">
  <link rel="icon" type="image/png" href="/img/2.jpg">
  <meta name="viewport"
        content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="description" content="">
  <meta name="author" content="K">
  <meta name="keywords" content="">
  <title>docker原生网络 - K</title>

  <link  rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/css/bootstrap.min.css" />


  <link  rel="stylesheet" href="https://cdn.staticfile.org/github-markdown-css/4.0.0/github-markdown.min.css" />
  <link  rel="stylesheet" href="/lib/hint/hint.min.css" />

  
    
    
      
      <link  rel="stylesheet" href="https://cdn.staticfile.org/highlight.js/10.0.0/styles/github-gist.min.css" />
    
  

  


<!-- 主题依赖的图标库，不要自行修改 -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_ba1fz6golrf.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_kmeydafke9r.css">


<link  rel="stylesheet" href="/css/main.css" />

<!-- 自定义样式保持在最底部 -->


  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
<meta name="generator" content="Hexo 5.2.0"></head>


<body>
  <header style="height: 70vh;">
    <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand"
       href="/">&nbsp;<strong>かい</strong>&nbsp;</a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" data-toggle="modal" data-target="#modalSearch">&nbsp;<i
                class="iconfont icon-search"></i>&nbsp;</a>
          </li>
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" href="javascript:">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div class="banner intro-2" id="background" parallax=true
         style="background: url('/img/1.jpg') no-repeat center center;
           background-size: cover;">
      <div class="full-bg-img">
        <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
          <div class="container page-header text-center fade-in-up">
            <span class="h2" id="subtitle">
              
            </span>

            
              <div class="mt-3">
  
  
    <span class="post-meta">
      <i class="iconfont icon-date-fill" aria-hidden="true"></i>
      <time datetime="2020-12-04 16:00" pubdate>
        2020年12月4日 下午
      </time>
    </span>
  
</div>

<div class="mt-1">
  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-chart"></i>
      3.9k 字
    </span>
  

  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-clock-fill"></i>
      
      
      59
       分钟
    </span>
  

  
  
</div>

            
          </div>

          
        </div>
      </div>
    </div>
  </header>

  <main>
    
      

<div class="container-fluid">
  <div class="row">
    <div class="d-none d-lg-block col-lg-2"></div>
    <div class="col-lg-8 nopadding-md">
      <div class="container nopadding-md" id="board-ctn">
        <div class="py-5" id="board">
          <article class="post-content mx-auto" id="post">
            <!-- SEO header -->
            <h1 style="display: none">docker原生网络</h1>
            
            <div class="markdown-body" id="post-body">
              <h2 id="docker原始网络"><a href="#docker原始网络" class="headerlink" title="docker原始网络"></a>docker原始网络</h2><ul>
<li>docker程序中自带的网络类型<pre><code class="hljs routeros">[root@localhost ~]# docker<span class="hljs-built_in"> network </span>ls
NETWORK ID          NAME                DRIVER              SCOPE
941f6aac20a0       <span class="hljs-built_in"> bridge </span>            <span class="hljs-built_in"> bridge </span>             local
433526ca900b        host                host                local
595c66e2ae10        none                <span class="hljs-literal">null</span>                local</code></pre></li>
<li>主要用于容器与容器之间以及外部的通讯</li>
</ul>
<h2 id="none网络"><a href="#none网络" class="headerlink" title="none网络"></a>none网络</h2><ul>
<li>无网络，意味着完全封闭，该模式关闭了容器的网络功能</li>
<li>主要用于生成密码或者二维码的情况下使用<pre><code class="hljs routeros">[root@localhost ~]# docker <span class="hljs-builtin-name">run</span> -itd --name test1 --network none busybox
a3adf8d8873124b8bf6aa4eff4c8ec157c1fa01b8d718fcf6da1df9bcbad343d
[root@localhost ~]# docker exec -it test1 sh
/ #<span class="hljs-built_in"> ip </span>a
1: lo: &lt;LOOPBACK,UP,LOWER_UP&gt; mtu 65536 qdisc noqueue qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
/ #<span class="hljs-built_in"> ping </span>www.baidu.com
ping: bad<span class="hljs-built_in"> address </span><span class="hljs-string">&#x27;www.baidu.com&#x27;</span>
<span class="hljs-comment"># 该容器只有一个本地回环地址，无法和外界通讯</span></code></pre>
<h2 id="host网络"><a href="#host网络" class="headerlink" title="host网络"></a>host网络</h2></li>
<li>仅主机模式，与物理机相连，高校高速情况下(lnmp分离部署)使用 ，与物理机的网络时一样的</li>
<li>容器将不会虚拟出自己的网卡，配置自己的ip 而是使用物理机的ip和端口<pre><code class="hljs angelscript"><span class="hljs-string">[root@localhost ~]</span># docker run -it --name test2 --network host busybox
/ # ip a
<span class="hljs-number">1</span>: lo: &lt;LOOPBACK,UP,LOWER_UP&gt; mtu <span class="hljs-number">65536</span> qdisc noqueue qlen <span class="hljs-number">1000</span>
    link/loopback <span class="hljs-number">00</span>:<span class="hljs-number">00</span>:<span class="hljs-number">00</span>:<span class="hljs-number">00</span>:<span class="hljs-number">00</span>:<span class="hljs-number">00</span> brd <span class="hljs-number">00</span>:<span class="hljs-number">00</span>:<span class="hljs-number">00</span>:<span class="hljs-number">00</span>:<span class="hljs-number">00</span>:<span class="hljs-number">00</span>
    inet <span class="hljs-number">127.0</span><span class="hljs-number">.0</span><span class="hljs-number">.1</span>/<span class="hljs-number">8</span> scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::<span class="hljs-number">1</span>/<span class="hljs-number">128</span> scope host
       valid_lft forever preferred_lft forever
<span class="hljs-number">2</span>: ens33: &lt;BROADCAST,MULTICAST,UP,LOWER_UP&gt; mtu <span class="hljs-number">1500</span> qdisc pfifo_fast qlen <span class="hljs-number">1000</span>
    link/ether <span class="hljs-number">00</span>:<span class="hljs-number">0</span>c:<span class="hljs-number">29</span>:b3:<span class="hljs-number">54</span>:<span class="hljs-number">61</span> brd ff:ff:ff:ff:ff:ff
    inet <span class="hljs-number">192.168</span><span class="hljs-number">.100</span><span class="hljs-number">.212</span>/<span class="hljs-number">24</span> brd <span class="hljs-number">192.168</span><span class="hljs-number">.100</span><span class="hljs-number">.255</span> scope global ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::a924:<span class="hljs-number">2f</span>d4:e68:<span class="hljs-number">388f</span>/<span class="hljs-number">64</span> scope link
       valid_lft forever preferred_lft forever
<span class="hljs-number">3</span>: virbr0: &lt;NO-CARRIER,BROADCAST,MULTICAST,UP&gt; mtu <span class="hljs-number">1500</span> qdisc noqueue qlen <span class="hljs-number">1000</span>
    link/ether <span class="hljs-number">52</span>:<span class="hljs-number">54</span>:<span class="hljs-number">00</span>:<span class="hljs-number">01</span>:<span class="hljs-number">38</span>:<span class="hljs-number">1</span>e brd ff:ff:ff:ff:ff:ff
    inet <span class="hljs-number">192.168</span><span class="hljs-number">.122</span><span class="hljs-number">.1</span>/<span class="hljs-number">24</span> brd <span class="hljs-number">192.168</span><span class="hljs-number">.122</span><span class="hljs-number">.255</span> scope global virbr0
       valid_lft forever preferred_lft forever
<span class="hljs-number">4</span>: virbr0-nic: &lt;BROADCAST,MULTICAST&gt; mtu <span class="hljs-number">1500</span> qdisc pfifo_fast master virbr0 qlen <span class="hljs-number">1000</span>
    link/ether <span class="hljs-number">52</span>:<span class="hljs-number">54</span>:<span class="hljs-number">00</span>:<span class="hljs-number">01</span>:<span class="hljs-number">38</span>:<span class="hljs-number">1</span>e brd ff:ff:ff:ff:ff:ff
<span class="hljs-number">5</span>: docker0: &lt;BROADCAST,MULTICAST,UP,LOWER_UP&gt; mtu <span class="hljs-number">1500</span> qdisc noqueue
    link/ether <span class="hljs-number">02</span>:<span class="hljs-number">42</span>:e9:f9:ae:<span class="hljs-number">33</span> brd ff:ff:ff:ff:ff:ff
    inet <span class="hljs-number">172.17</span><span class="hljs-number">.0</span><span class="hljs-number">.1</span>/<span class="hljs-number">16</span> brd <span class="hljs-number">172.17</span><span class="hljs-number">.255</span><span class="hljs-number">.255</span> scope global docker0
       valid_lft forever preferred_lft forever
    inet6 fe80::<span class="hljs-number">42</span>:e9ff:fef9:ae33/<span class="hljs-number">64</span> scope link
       valid_lft forever preferred_lft forever
<span class="hljs-number">9</span>: <span class="hljs-symbol">veth239b5f1@</span>if8: &lt;BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN&gt; mtu <span class="hljs-number">1500</span> qdisc noqueue master docker0
    link/ether be:<span class="hljs-number">85</span>:de:<span class="hljs-number">66</span>:<span class="hljs-number">56</span>:b2 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::bc85:deff:fe66:<span class="hljs-number">56</span>b2/<span class="hljs-number">64</span> scope link
       valid_lft forever preferred_lft forever

/ # ping www.baidu.com
PING www.baidu.com (<span class="hljs-number">39.156</span><span class="hljs-number">.66</span><span class="hljs-number">.18</span>): <span class="hljs-number">56</span> data bytes
<span class="hljs-number">64</span> bytes <span class="hljs-keyword">from</span> <span class="hljs-number">39.156</span><span class="hljs-number">.66</span><span class="hljs-number">.18</span>: seq=<span class="hljs-number">0</span> ttl=<span class="hljs-number">128</span> time=<span class="hljs-number">7.745</span> ms

# host用的是物理机的网络</code></pre>
<h2 id="joined网络"><a href="#joined网络" class="headerlink" title="joined网络"></a>joined网络</h2></li>
<li>joined容器是另一中实现容器之间通信的方式</li>
<li>可以使两个或者多个容器共享一个网络栈，共享网卡和配置信息，joined容器之间可以通过127.0.0.1直接通信</li>
<li>可以用于监控其他容器或者希望高效率快速通信</li>
<li>使用方法<pre><code class="hljs angelscript"><span class="hljs-string">[root@localhost ~]</span># docker run -itd --name test3 httpd
<span class="hljs-number">8</span>bc7a8d66aa9b0fedb260eb5435724d45f43c18717bd5b6d17f5a2e523ddd3bd</code></pre></li>
<li>在上述例子中，test容器启动之后，想要知道这个容器的ip是多少，进入容器发现没有命令，几乎什么常用命令都没有，更没有关于网卡的配置</li>
<li>这时候需要使用另一个容器，且这个容器不能使用和以上例子中相同的镜像，否则还是没有任何命令，使用joined共享它的网络来达到查看ip的目的<blockquote>
<p>–network container:test：表示启动此容器要使用容器test的网络配置</p>
</blockquote>
<pre><code class="hljs angelscript"><span class="hljs-string">[root@localhost ~]</span># docker run -itd --network container:test3 --name test4 busybox
<span class="hljs-number">901</span>ee495dff3c6e189b3c4e7e6a6d702dfe4961e608f3c6dc38072a32634a6e7
<span class="hljs-string">[root@localhost ~]</span># docker exec -it test4 sh
/ # ip a
<span class="hljs-number">1</span>: lo: &lt;LOOPBACK,UP,LOWER_UP&gt; mtu <span class="hljs-number">65536</span> qdisc noqueue qlen <span class="hljs-number">1000</span>
    link/loopback <span class="hljs-number">00</span>:<span class="hljs-number">00</span>:<span class="hljs-number">00</span>:<span class="hljs-number">00</span>:<span class="hljs-number">00</span>:<span class="hljs-number">00</span> brd <span class="hljs-number">00</span>:<span class="hljs-number">00</span>:<span class="hljs-number">00</span>:<span class="hljs-number">00</span>:<span class="hljs-number">00</span>:<span class="hljs-number">00</span>
    inet <span class="hljs-number">127.0</span><span class="hljs-number">.0</span><span class="hljs-number">.1</span>/<span class="hljs-number">8</span> scope host lo
       valid_lft forever preferred_lft forever
<span class="hljs-number">10</span>: <span class="hljs-symbol">eth0@</span>if11: &lt;BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN&gt; mtu <span class="hljs-number">1500</span> qdisc noqueue
    link/ether <span class="hljs-number">02</span>:<span class="hljs-number">42</span>:ac:<span class="hljs-number">11</span>:<span class="hljs-number">00</span>:<span class="hljs-number">03</span> brd ff:ff:ff:ff:ff:ff
    inet <span class="hljs-number">172.17</span><span class="hljs-number">.0</span><span class="hljs-number">.3</span>/<span class="hljs-number">16</span> brd <span class="hljs-number">172.17</span><span class="hljs-number">.255</span><span class="hljs-number">.255</span> scope global eth0
       valid_lft forever preferred_lft forever</code></pre></li>
<li>可以看到 10网卡就是test3的ip 它和test4共享一个ip 可以理解他们在一个网络命名空间内<blockquote>
<p>访问httpd页面(因为test3是httpd容器，所以访问ip是可以看到页面的)</p>
</blockquote>
<pre><code class="hljs gherkin">[root<span class="hljs-meta">@localhost</span> ~]<span class="hljs-comment"># curl 172.17.0.3</span>
<span class="hljs-variable">&lt;html&gt;</span><span class="hljs-variable">&lt;body&gt;</span><span class="hljs-variable">&lt;h1&gt;</span>It works!<span class="hljs-variable">&lt;/h1&gt;</span><span class="hljs-variable">&lt;/body&gt;</span><span class="hljs-variable">&lt;/html&gt;</span></code></pre>

</li>
</ul>
<h2 id="bridge网络"><a href="#bridge网络" class="headerlink" title="bridge网络"></a>bridge网络</h2><ul>
<li>容器的桥接网络</li>
<li>开启容器后会有一个docker0 网络，如果不指定network，之后所有的网络默认指定docker0这块桥接卡 地址是172.17.0.1</li>
</ul>
<pre><code class="hljs routeros">[root@localhost ~]#<span class="hljs-built_in"> ip </span>a
<span class="hljs-built_in">..</span>.
5: docker0: &lt;NO-CARRIER,BROADCAST,MULTICAST,UP&gt; mtu 1500 qdisc noqueue state DOWN<span class="hljs-built_in"> group default </span>
    link/ether 02:42:31:92:1c:1e brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
       valid_lft forever preferred_lft forever
    inet6 fe80::42:31ff:fe92:1c1e/64 scope link 
       valid_lft forever preferred_lft forever</code></pre>
<ul>
<li><p>在docker0后面，有一个NO-CARRIER，表示它不用来传输任何的数据的，只有在没有任何容器运行时，才会出现这个NO-CARRIER，这个网卡也被叫做桥接网卡</p>
<blockquote>
<p>查看用来控制桥接网卡的信息</p>
</blockquote>
<pre><code class="hljs routeros">[root@localhost ~]# brctl show
bridge name<span class="hljs-built_in">	bridge </span>id		STP enabled	interfaces
docker0		8000.024231921c1e	<span class="hljs-literal">no</span>		
virbr0		8000.525400fa47fa	<span class="hljs-literal">yes</span>		virbr0-nic
</code></pre></li>
<li><p>docker0网卡的唯一作用是用来桥接的，根据以上信息中看到docker0的interfaces是没有信息的。这是因为它还没有为任何网络接口进行桥接</p>
</li>
<li><p>创建一个容器并使用桥接网络（默认就是桥接），也可以使用–network bridge</p>
<pre><code class="hljs routeros">[root@localhost ~]# docker <span class="hljs-builtin-name">run</span> -itd --name http httpd
7bb31f4cb002b1ff293de1d1edd892b0d62aaa32cc779fb790b0a55933ae3ab3
[root@localhost ~]# brctl show  # 再次查看时已经有了桥接的网络接口
bridge name<span class="hljs-built_in">	bridge </span>id		STP enabled	interfaces
docker0         8000.024212222064       <span class="hljs-literal">no</span>              vethffb20a5
virbr0          8000.525400bb511b       <span class="hljs-literal">yes</span>             virbr0-nic
</code></pre>
<blockquote>
<p>通过joined网络来查看该容器的网卡信息</p>
</blockquote>
<pre><code class="hljs angelscript"><span class="hljs-string">[root@localhost ~]</span># docker run -it --name tt --network container:http busybox
/ # ip a
<span class="hljs-number">1</span>: lo: &lt;LOOPBACK,UP,LOWER_UP&gt; mtu <span class="hljs-number">65536</span> qdisc noqueue qlen <span class="hljs-number">1000</span>
    link/loopback <span class="hljs-number">00</span>:<span class="hljs-number">00</span>:<span class="hljs-number">00</span>:<span class="hljs-number">00</span>:<span class="hljs-number">00</span>:<span class="hljs-number">00</span> brd <span class="hljs-number">00</span>:<span class="hljs-number">00</span>:<span class="hljs-number">00</span>:<span class="hljs-number">00</span>:<span class="hljs-number">00</span>:<span class="hljs-number">00</span>
    inet <span class="hljs-number">127.0</span><span class="hljs-number">.0</span><span class="hljs-number">.1</span>/<span class="hljs-number">8</span> scope host lo
       valid_lft forever preferred_lft forever
<span class="hljs-number">10</span>: <span class="hljs-symbol">eth0@</span>if11: &lt;BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN&gt; mtu <span class="hljs-number">1500</span> qdisc noqueue
    link/ether <span class="hljs-number">02</span>:<span class="hljs-number">42</span>:ac:<span class="hljs-number">11</span>:<span class="hljs-number">00</span>:<span class="hljs-number">02</span> brd ff:ff:ff:ff:ff:ff
    inet <span class="hljs-number">172.17</span><span class="hljs-number">.0</span><span class="hljs-number">.2</span>/<span class="hljs-number">16</span> brd <span class="hljs-number">172.17</span><span class="hljs-number">.255</span><span class="hljs-number">.255</span> scope global eth0
       valid_lft forever preferred_lft forever
# 可以看到容器的网卡是 <span class="hljs-number">10</span>: <span class="hljs-symbol">eth0@</span>if11
# 表示接口<span class="hljs-number">10</span> 桥接到 接口<span class="hljs-number">11</span>上了</code></pre>
<blockquote>
<p>主机查看网卡信息</p>
</blockquote>
<pre><code class="hljs angelscript"><span class="hljs-string">[root@localhost ~]</span># ip a
<span class="hljs-number">5</span>: docker0: &lt;BROADCAST,MULTICAST,UP,LOWER_UP&gt; mtu <span class="hljs-number">1500</span> qdisc noqueue state UP group <span class="hljs-keyword">default</span>
    link/ether <span class="hljs-number">02</span>:<span class="hljs-number">42</span>:<span class="hljs-number">12</span>:<span class="hljs-number">22</span>:<span class="hljs-number">20</span>:<span class="hljs-number">64</span> brd ff:ff:ff:ff:ff:ff
    inet <span class="hljs-number">172.17</span><span class="hljs-number">.0</span><span class="hljs-number">.1</span>/<span class="hljs-number">16</span> brd <span class="hljs-number">172.17</span><span class="hljs-number">.255</span><span class="hljs-number">.255</span> scope global docker0
       valid_lft forever preferred_lft forever
    inet6 fe80::<span class="hljs-number">42</span>:<span class="hljs-number">12f</span>f:fe22:<span class="hljs-number">2064</span>/<span class="hljs-number">64</span> scope link
       valid_lft forever preferred_lft forever
<span class="hljs-number">11</span>: <span class="hljs-symbol">vethffb20a5@</span>if10: &lt;BROADCAST,MULTICAST,UP,LOWER_UP&gt; mtu <span class="hljs-number">1500</span> qdisc noqueue master docker0 state UP group <span class="hljs-keyword">default</span>
    link/ether <span class="hljs-number">2</span>a:<span class="hljs-number">54</span>:<span class="hljs-number">0</span>a:<span class="hljs-number">56</span>:e1:<span class="hljs-number">6</span>a brd ff:ff:ff:ff:ff:ff link-netnsid <span class="hljs-number">0</span>
    inet6 fe80::<span class="hljs-number">2854</span>:aff:fe56:e16a/<span class="hljs-number">64</span> scope link
       valid_lft forever preferred_lft forever</code></pre></li>
<li><p>主机的网卡中可以看到11: vethffb20a5@if10，而刚才使用brctl show查看到的桥接接口信息就是vethffb20a5，所以vethffb20a5又桥接在docker0上，所以docker0和容器中的ip网段是一样的，可以通信</p>
</li>
<li><p>如果要查看bridge的详细信息可以通过<br><code>docker network inspect bridge</code></p>
</li>
</ul>
<h2 id="自定义网络"><a href="#自定义网络" class="headerlink" title="自定义网络"></a>自定义网络</h2><p> <code>docker network create --driver 网卡类型 网卡名称</code></p>
<pre><code class="hljs routeros">[root@localhost ~]# docker<span class="hljs-built_in"> network </span>create --driver<span class="hljs-built_in"> bridge </span>my_net
55521fcf1e3a9cb715ebf753c11c645d62567d689b6de41fc9e93f012e3da2df
[root@localhost ~]# docker<span class="hljs-built_in"> network </span>ls
NETWORK ID          NAME                DRIVER              SCOPE
8243bd0fab55       <span class="hljs-built_in"> bridge </span>            <span class="hljs-built_in"> bridge </span>             local
dc088ea51e19        host                host                local
55521fcf1e3a        my_net             <span class="hljs-built_in"> bridge </span>             local
cec68349a7d5        none                <span class="hljs-literal">null</span>                local
[root@localhost ~]# brctl show
bridge name    <span class="hljs-built_in"> bridge </span>id               STP enabled     interfaces
br-55521fcf1e3a         8000.02426a7b44e2       <span class="hljs-literal">no</span>
docker0         8000.024212222064       <span class="hljs-literal">no</span>              vethffb20a5
virbr0          8000.525400bb511b       <span class="hljs-literal">yes</span>             virbr0-nic
</code></pre>
<ul>
<li>可以看到多了一个mynet网卡 和多了一个br-55521fcf1e3a网卡</li>
<li>该网卡会自动向后分配ip地址 也就是 172.18.0.1<pre><code class="hljs routeros">[root@localhost ~]# docker<span class="hljs-built_in"> network </span>inspect my_net
[
    &#123;
        <span class="hljs-string">&quot;Name&quot;</span>: <span class="hljs-string">&quot;my_net&quot;</span>, 
        <span class="hljs-string">&quot;Id&quot;</span>: <span class="hljs-string">&quot;55521fcf1e3a9cb715ebf753c11c645d62567d689b6de41fc9e93f012e3da2df&quot;</span>,
        <span class="hljs-string">&quot;Created&quot;</span>: <span class="hljs-string">&quot;2020-12-06T01:20:14.924737067+08:00&quot;</span>,
        <span class="hljs-string">&quot;Scope&quot;</span>: <span class="hljs-string">&quot;local&quot;</span>,
        <span class="hljs-string">&quot;Driver&quot;</span>: <span class="hljs-string">&quot;bridge&quot;</span>,
        <span class="hljs-string">&quot;EnableIPv6&quot;</span>: <span class="hljs-literal">false</span>,
        <span class="hljs-string">&quot;IPAM&quot;</span>: &#123;
            <span class="hljs-string">&quot;Driver&quot;</span>: <span class="hljs-string">&quot;default&quot;</span>,
            <span class="hljs-string">&quot;Options&quot;</span>: &#123;&#125;,
            <span class="hljs-string">&quot;Config&quot;</span>: [
                &#123;
                    <span class="hljs-string">&quot;Subnet&quot;</span>: <span class="hljs-string">&quot;172.18.0.0/16&quot;</span>,
                    <span class="hljs-string">&quot;Gateway&quot;</span>: <span class="hljs-string">&quot;172.18.0.1&quot;</span>
                &#125;
            ]
        &#125;,
<span class="hljs-comment"># 可以看到my_net地址为18网段，初始的桥接网卡是17，就可以发现自动分配的网段是网上递增的。</span></code></pre>

</li>
</ul>
<h2 id="创建手动分配网段的网卡"><a href="#创建手动分配网段的网卡" class="headerlink" title="创建手动分配网段的网卡"></a>创建手动分配网段的网卡</h2><p><code>docker network create --driver 网卡类型 --subnet 网段/子网 --gateway 网关 网卡名</code></p>
<pre><code class="hljs routeros">[root@localhost ~]# docker<span class="hljs-built_in"> network </span>create --driver<span class="hljs-built_in"> bridge </span>--subnet 172.22.22.0/24 --gateway 172.22.22.1 my_net2
37f0337352755ae045f879c8e4e9ce4ab628615cc611114f563186d789313fe2

[root@localhost ~]#<span class="hljs-built_in"> ip </span>a
13: br-37f033735275: &lt;NO-CARRIER,BROADCAST,MULTICAST,UP&gt; mtu 1500 qdisc noqueue state DOWN<span class="hljs-built_in"> group </span>default
    link/ether 02:42:66:73:37:48 brd ff:ff:ff:ff:ff:ff
    inet 172.22.22.1/24 brd 172.22.22.255 scope global br-37f033735275
       valid_lft forever preferred_lft forever</code></pre>

<h2 id="使用自定义网卡"><a href="#使用自定义网卡" class="headerlink" title="使用自定义网卡"></a>使用自定义网卡</h2><ul>
<li>使用–network指定新创建的网卡名称即可使用</li>
</ul>
<blockquote>
<p>使用自定义网卡创建容器</p>
</blockquote>
<pre><code class="hljs angelscript"><span class="hljs-string">[root@localhost ~]</span># docker run -itd --name test_lmk --network my_net2 busybox
c9867b65167c630ca750030a664d0e6e02e103a217286af0d33be5d2c3313787

<span class="hljs-string">[root@localhost ~]</span># docker exec -it test_lmk sh
/ # ip a
<span class="hljs-number">1</span>: lo: &lt;LOOPBACK,UP,LOWER_UP&gt; mtu <span class="hljs-number">65536</span> qdisc noqueue qlen <span class="hljs-number">1000</span>
    link/loopback <span class="hljs-number">00</span>:<span class="hljs-number">00</span>:<span class="hljs-number">00</span>:<span class="hljs-number">00</span>:<span class="hljs-number">00</span>:<span class="hljs-number">00</span> brd <span class="hljs-number">00</span>:<span class="hljs-number">00</span>:<span class="hljs-number">00</span>:<span class="hljs-number">00</span>:<span class="hljs-number">00</span>:<span class="hljs-number">00</span>
    inet <span class="hljs-number">127.0</span><span class="hljs-number">.0</span><span class="hljs-number">.1</span>/<span class="hljs-number">8</span> scope host lo
       valid_lft forever preferred_lft forever
<span class="hljs-number">14</span>: <span class="hljs-symbol">eth0@</span>if15: &lt;BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN&gt; mtu <span class="hljs-number">1500</span> qdisc noqueue
    link/ether <span class="hljs-number">02</span>:<span class="hljs-number">42</span>:ac:<span class="hljs-number">16</span>:<span class="hljs-number">16</span>:<span class="hljs-number">02</span> brd ff:ff:ff:ff:ff:ff
    inet <span class="hljs-number">172.22</span><span class="hljs-number">.22</span><span class="hljs-number">.2</span>/<span class="hljs-number">24</span> brd <span class="hljs-number">172.22</span><span class="hljs-number">.22</span><span class="hljs-number">.255</span> scope global eth0
       valid_lft forever preferred_lft forever</code></pre>

<h2 id="容器自定义ip"><a href="#容器自定义ip" class="headerlink" title="容器自定义ip"></a>容器自定义ip</h2><ul>
<li>只能给自定义网卡的容器设置ip docker0无法设置</li>
<li>通过 –ip 参数设置ip<blockquote>
<p>设置容器ip为 172.22.22.100</p>
</blockquote>
<pre><code class="hljs angelscript"><span class="hljs-string">[root@localhost ~]</span># docker run -it --name test_kml --network my_net2 --ip <span class="hljs-number">172.22</span><span class="hljs-number">.22</span><span class="hljs-number">.100</span> busybox
/ # ip a
<span class="hljs-number">1</span>: lo: &lt;LOOPBACK,UP,LOWER_UP&gt; mtu <span class="hljs-number">65536</span> qdisc noqueue qlen <span class="hljs-number">1000</span>
    link/loopback <span class="hljs-number">00</span>:<span class="hljs-number">00</span>:<span class="hljs-number">00</span>:<span class="hljs-number">00</span>:<span class="hljs-number">00</span>:<span class="hljs-number">00</span> brd <span class="hljs-number">00</span>:<span class="hljs-number">00</span>:<span class="hljs-number">00</span>:<span class="hljs-number">00</span>:<span class="hljs-number">00</span>:<span class="hljs-number">00</span>
    inet <span class="hljs-number">127.0</span><span class="hljs-number">.0</span><span class="hljs-number">.1</span>/<span class="hljs-number">8</span> scope host lo
       valid_lft forever preferred_lft forever
<span class="hljs-number">16</span>: <span class="hljs-symbol">eth0@</span>if17: &lt;BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN&gt; mtu <span class="hljs-number">1500</span> qdisc noqueue
    link/ether <span class="hljs-number">02</span>:<span class="hljs-number">42</span>:ac:<span class="hljs-number">16</span>:<span class="hljs-number">16</span>:<span class="hljs-number">64</span> brd ff:ff:ff:ff:ff:ff
    inet <span class="hljs-number">172.22</span><span class="hljs-number">.22</span><span class="hljs-number">.100</span>/<span class="hljs-number">24</span> brd <span class="hljs-number">172.22</span><span class="hljs-number">.22</span><span class="hljs-number">.255</span> scope global eth0
       valid_lft forever preferred_lft forever</code></pre>

</li>
</ul>
<h2 id="容器跨网段通信"><a href="#容器跨网段通信" class="headerlink" title="容器跨网段通信"></a>容器跨网段通信</h2><p><img src="/images/docker/kwd.png" srcset="/img/loading.gif"></p>
<ul>
<li>mynet2的网段是 172.22.22.0/24</li>
<li>docker0的网段是 172.17.0.0/24</li>
<li>两个网端的容器进行相互通信<pre><code class="hljs angelscript"># 发现mynet2网卡内的容器可以ping同docker0，但是ping不同docker0内的容器，是因为防火墙转发导致的
/ # ip a
<span class="hljs-number">1</span>: lo: &lt;LOOPBACK,UP,LOWER_UP&gt; mtu <span class="hljs-number">65536</span> qdisc noqueue qlen <span class="hljs-number">1000</span>
    link/loopback <span class="hljs-number">00</span>:<span class="hljs-number">00</span>:<span class="hljs-number">00</span>:<span class="hljs-number">00</span>:<span class="hljs-number">00</span>:<span class="hljs-number">00</span> brd <span class="hljs-number">00</span>:<span class="hljs-number">00</span>:<span class="hljs-number">00</span>:<span class="hljs-number">00</span>:<span class="hljs-number">00</span>:<span class="hljs-number">00</span>
    inet <span class="hljs-number">127.0</span><span class="hljs-number">.0</span><span class="hljs-number">.1</span>/<span class="hljs-number">8</span> scope host lo
       valid_lft forever preferred_lft forever
<span class="hljs-number">18</span>: <span class="hljs-symbol">eth0@</span>if19: &lt;BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN&gt; mtu <span class="hljs-number">1500</span> qdisc noqueue
    link/ether <span class="hljs-number">02</span>:<span class="hljs-number">42</span>:ac:<span class="hljs-number">16</span>:<span class="hljs-number">16</span>:<span class="hljs-number">64</span> brd ff:ff:ff:ff:ff:ff
    inet <span class="hljs-number">172.22</span><span class="hljs-number">.22</span><span class="hljs-number">.100</span>/<span class="hljs-number">24</span> brd <span class="hljs-number">172.22</span><span class="hljs-number">.22</span><span class="hljs-number">.255</span> scope global eth0
       valid_lft forever preferred_lft forever
/ # ping <span class="hljs-number">172.17</span><span class="hljs-number">.0</span><span class="hljs-number">.1</span>
PING <span class="hljs-number">172.17</span><span class="hljs-number">.0</span><span class="hljs-number">.1</span> (<span class="hljs-number">172.17</span><span class="hljs-number">.0</span><span class="hljs-number">.1</span>): <span class="hljs-number">56</span> data bytes
<span class="hljs-number">64</span> bytes <span class="hljs-keyword">from</span> <span class="hljs-number">172.17</span><span class="hljs-number">.0</span><span class="hljs-number">.1</span>: seq=<span class="hljs-number">0</span> ttl=<span class="hljs-number">64</span> time=<span class="hljs-number">0.193</span> ms

/ # ping <span class="hljs-number">172.17</span><span class="hljs-number">.0</span><span class="hljs-number">.2</span>
PING <span class="hljs-number">172.17</span><span class="hljs-number">.0</span><span class="hljs-number">.2</span> (<span class="hljs-number">172.17</span><span class="hljs-number">.0</span><span class="hljs-number">.2</span>): <span class="hljs-number">56</span> data bytes
</code></pre></li>
<li>查看防火前转发信息<pre><code class="hljs mipsasm">[root@localhost ~]<span class="hljs-comment"># iptables-save</span>
<span class="hljs-comment"># 查看关键信息</span>
-A DOCKER-ISOLATION-STAGE<span class="hljs-number">-2</span> -o <span class="hljs-keyword">br-37f033735275 </span>-<span class="hljs-keyword">j </span>DROP
-A DOCKER-ISOLATION-STAGE<span class="hljs-number">-2</span> -o <span class="hljs-keyword">br-55521fcf1e3a </span>-<span class="hljs-keyword">j </span>DROP
-A DOCKER-ISOLATION-STAGE<span class="hljs-number">-2</span> -o docker0 -<span class="hljs-keyword">j </span>DROP
<span class="hljs-comment"># 以上表示去往br-37f033735275和br-55521fcf1e3a这两块网卡的数据会被删除</span>
<span class="hljs-comment"># 正是我们刚才创建的两块bridge网卡的id号</span>
<span class="hljs-comment"># 不仅这两个网卡的被drop了，docker的也是一样，所以docker0不能和这两块网卡进行互相通信</span>

<span class="hljs-comment"># 如果想要去通讯，可以去把防火墙关掉，但是上网的访问，还需要通过防火墙来转换ip，不能去关闭，或者清除防火墙。</span></code></pre>
<blockquote>
<p>运行一个docker0网卡的httpd容器，并给该容器添加my_net2网卡<br><code>docker network connect 自定义桥接网卡名 连接到的容器名/id</code> </p>
</blockquote>
</li>
<li>上面的命令可以为容器添加其他网卡<pre><code class="hljs angelscript"><span class="hljs-string">[root@localhost ~]</span># docker run -itd --name http_lmk httpd
<span class="hljs-number">2e47327</span>bfb67eae9a60c591c491ff6ee1b7917c83099e2a63a417677bc06bd5a
<span class="hljs-string">[root@localhost ~]</span># docker network connect my_net2 http_lmk
# 查看httpd的ip
<span class="hljs-string">[root@localhost ~]</span># docker run -it --name kkk --network container:http_lmk busybox
/ # ip a
<span class="hljs-number">1</span>: lo: &lt;LOOPBACK,UP,LOWER_UP&gt; mtu <span class="hljs-number">65536</span> qdisc noqueue qlen <span class="hljs-number">1000</span>
    link/loopback <span class="hljs-number">00</span>:<span class="hljs-number">00</span>:<span class="hljs-number">00</span>:<span class="hljs-number">00</span>:<span class="hljs-number">00</span>:<span class="hljs-number">00</span> brd <span class="hljs-number">00</span>:<span class="hljs-number">00</span>:<span class="hljs-number">00</span>:<span class="hljs-number">00</span>:<span class="hljs-number">00</span>:<span class="hljs-number">00</span>
    inet <span class="hljs-number">127.0</span><span class="hljs-number">.0</span><span class="hljs-number">.1</span>/<span class="hljs-number">8</span> scope host lo
       valid_lft forever preferred_lft forever
<span class="hljs-number">20</span>: <span class="hljs-symbol">eth0@</span>if21: &lt;BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN&gt; mtu <span class="hljs-number">1500</span> qdisc noqueue
    link/ether <span class="hljs-number">02</span>:<span class="hljs-number">42</span>:ac:<span class="hljs-number">11</span>:<span class="hljs-number">00</span>:<span class="hljs-number">03</span> brd ff:ff:ff:ff:ff:ff
    inet <span class="hljs-number">172.17</span><span class="hljs-number">.0</span><span class="hljs-number">.3</span>/<span class="hljs-number">16</span> brd <span class="hljs-number">172.17</span><span class="hljs-number">.255</span><span class="hljs-number">.255</span> scope global eth0
       valid_lft forever preferred_lft forever
<span class="hljs-number">22</span>: <span class="hljs-symbol">eth1@</span>if23: &lt;BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN&gt; mtu <span class="hljs-number">1500</span> qdisc noqueue
    link/ether <span class="hljs-number">02</span>:<span class="hljs-number">42</span>:ac:<span class="hljs-number">16</span>:<span class="hljs-number">16</span>:<span class="hljs-number">03</span> brd ff:ff:ff:ff:ff:ff
    inet <span class="hljs-number">172.22</span><span class="hljs-number">.22</span><span class="hljs-number">.3</span>/<span class="hljs-number">24</span> brd <span class="hljs-number">172.22</span><span class="hljs-number">.22</span><span class="hljs-number">.255</span> scope global eth1
       valid_lft forever preferred_lft forever
# 可以看到 httpd容器中有两个网卡
# 一块ip是 <span class="hljs-number">172.17</span><span class="hljs-number">.0</span><span class="hljs-number">.3</span>
# 一块ip是 <span class="hljs-number">172.22</span><span class="hljs-number">.22</span><span class="hljs-number">.3</span>

# 现在ping my_net2的 <span class="hljs-number">172.22</span><span class="hljs-number">.22</span><span class="hljs-number">.100</span>
/ # ping <span class="hljs-number">172.22</span><span class="hljs-number">.22</span><span class="hljs-number">.100</span>
PING <span class="hljs-number">172.22</span><span class="hljs-number">.22</span><span class="hljs-number">.100</span> (<span class="hljs-number">172.22</span><span class="hljs-number">.22</span><span class="hljs-number">.100</span>): <span class="hljs-number">56</span> data bytes
<span class="hljs-number">64</span> bytes <span class="hljs-keyword">from</span> <span class="hljs-number">172.22</span><span class="hljs-number">.22</span><span class="hljs-number">.100</span>: seq=<span class="hljs-number">0</span> ttl=<span class="hljs-number">64</span> time=<span class="hljs-number">0.303</span> ms
# 可以ping通

# 而<span class="hljs-number">172.22</span><span class="hljs-number">.22</span><span class="hljs-number">.100</span>那台容器需要ping 该容器的<span class="hljs-number">22</span>号网卡的ip才可以进行通信</code></pre></li>
<li>网段之间确实是没有办法通信，只能通过双网卡的方式来做到，间接的达到不同网段容器的通信</li>
</ul>
<h2 id="外网与容器之间访问的原理"><a href="#外网与容器之间访问的原理" class="headerlink" title="外网与容器之间访问的原理"></a>外网与容器之间访问的原理</h2><ul>
<li><p>默认情况下运行一个容器都能够去访问到外网，实际本质不是外网，是可以访问除本网络以外的网络</p>
</li>
<li><p>容器之所以可以访问到外网是通过路由表在通过物理机的ens33网卡转发到外网，然后再回来</p>
<blockquote>
<p>以其中docker0为例，这部分信息表示，如果docker0收到的源地址是172.17.0.0网段的数据，但目的并不是docker0的地址时，就交给MASQUERADE（伪装），而伪装就是将源地址转换为物理机的ip，也就是172.17.0.0网段的容器要访问其他网段时，去替换为主机ip</p>
</blockquote>
<ul>
<li>也可以这样理解<blockquote>
<p>物理机默认将来自容器的网段数据包通过docker0转发出去(就是docker0只要收到来自容器的网段数据请求就立刻转发，通过nat转换到本地主机网卡，在转发到外网)</p>
</blockquote>
</li>
</ul>
</li>
<li><p>DNAT 局域网内的主机将网络发布出去，供外网主机访问(就是 将内网地址转换为公网地址)</p>
</li>
<li><p>SNAT 通过网络访问其他外网数据时用SNAT(容器访问外网用的是SNAT)</p>
</li>
</ul>
<p><img src="/images/docker/zf.png" srcset="/img/loading.gif"></p>
<ul>
<li>根据上图来看</li>
<li>这里防火墙中的POSTROUTING，表示经过路由表之后检查数据包，PREROUTING是进入路由表之前检查数据包是否符合策略，而FORWORDING是查看路由表转发过程。相比来说FORWARDING比较好一点</li>
</ul>
<h2 id="外网访问容器-端口映射"><a href="#外网访问容器-端口映射" class="headerlink" title="外网访问容器(端口映射)"></a>外网访问容器(端口映射)</h2><p><img src="/images/docker/wn.png" srcset="/img/loading.gif"></p>
<ul>
<li>要通过端口映射来实现，docker0要将容器内访问的端口映射到物理机</li>
<li>这个端口要与httpd镜像中服务的端口一致<pre><code class="hljs angelscript"><span class="hljs-string">[root@localhost ~]</span># docker run -d -p <span class="hljs-number">80</span> httpd
<span class="hljs-number">8</span>d3342b4689a5972ffb354572c60e5149afc7689bbc182a3d1b12a71c4655cff
<span class="hljs-string">[root@localhost ~]</span># docker ps
CONTAINER ID        IMAGE               COMMAND              CREATED             STATUS              PORTS                   NAMES
<span class="hljs-number">8</span>d3342b4689a        httpd               <span class="hljs-string">&quot;httpd-foreground&quot;</span>   <span class="hljs-number">5</span> seconds ago       Up <span class="hljs-number">4</span> seconds        <span class="hljs-number">0.0</span><span class="hljs-number">.0</span><span class="hljs-number">.0</span>:<span class="hljs-number">32768</span>-&gt;<span class="hljs-number">80</span>/tcp   wonderful_turing
# 注意看以上输出信息中主机端口与容器端口的映射<span class="hljs-number">0.0</span><span class="hljs-number">.0</span><span class="hljs-number">.0</span>:<span class="hljs-number">32768</span>-&gt;<span class="hljs-number">80</span>/tcp
# 主机端口为<span class="hljs-number">32768</span>，容器中为<span class="hljs-number">80</span>，这时候访问物理机的<span class="hljs-number">32768</span>端口即可
<span class="hljs-string">[root@localhost ~]</span># curl <span class="hljs-number">192.168</span><span class="hljs-number">.100</span><span class="hljs-number">.211</span>:<span class="hljs-number">32768</span>
&lt;html&gt;&lt;body&gt;&lt;h1&gt;It works!&lt;/h1&gt;&lt;/body&gt;&lt;/html&gt;

# 查看容器对主机的端口映射
<span class="hljs-string">[root@localhost ~]</span># docker port wonderful_turing
<span class="hljs-number">80</span>/tcp -&gt; <span class="hljs-number">0.0</span><span class="hljs-number">.0</span><span class="hljs-number">.0</span>:<span class="hljs-number">32768</span>

# -p <span class="hljs-number">80</span> 是 将容器内的 <span class="hljs-number">80</span>端口映射出来，然后物理机根据自身的端口分配</code></pre></li>
<li>也可以指定主机使用什么端口来映射容器的80段口<pre><code class="hljs angelscript"><span class="hljs-string">[root@localhost ~]</span># docker run -itd -p <span class="hljs-number">8080</span>:<span class="hljs-number">80</span> httpd
<span class="hljs-number">6</span>d45ca89d6f5a3a6fc636a557b1251c88c93e6c89261133061d86164605a1117
<span class="hljs-string">[root@localhost ~]</span># curl <span class="hljs-number">192.168</span><span class="hljs-number">.100</span><span class="hljs-number">.211</span>:<span class="hljs-number">8080</span>
&lt;html&gt;&lt;body&gt;&lt;h1&gt;It works!&lt;/h1&gt;&lt;/body&gt;&lt;/html&gt;

# -p <span class="hljs-number">8080</span>:<span class="hljs-number">80</span> 是将容器的<span class="hljs-number">80</span>端口映射到物理机的<span class="hljs-number">8080</span>端口</code></pre></li>
<li>这个过程中，我们看上图中的下半部分，也就是红色线的部分，当我们作为client去访问物理的映射端口8080时，会出现一个docker proxy的代理去找这个8080映射在哪个ip的哪个端口，然后通过docker0网卡，获取到容器的数据</li>
</ul>

            </div>
            <hr>
            <div>
              <div class="post-metas mb-3">
                
                  <div class="post-meta mr-3">
                    <i class="iconfont icon-category"></i>
                    
                      <a class="hover-with-bg" href="/categories/docker/">docker</a>
                    
                  </div>
                
                
                  <div class="post-meta">
                    <i class="iconfont icon-tags"></i>
                    
                      <a class="hover-with-bg" href="/tags/docker/">docker</a>
                    
                  </div>
                
              </div>
              
                <p class="note note-warning">本博客所有文章是以学习为目的，如果有不对的地方可以一起交流沟通共同学习 邮箱:1248287831@qq.com！</p>
              
              
                <div class="post-prevnext row">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2020/12/07/docker-%E5%AE%B9%E5%99%A8%E6%8C%81%E4%B9%85%E5%8C%96/">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">docker-容器持久化</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2020/12/04/docker%E5%AE%B9%E5%99%A8%E7%9A%84%E7%8A%B6%E6%80%81/">
                        <span class="hidden-mobile">docker容器的状态</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>
    
      <div class="d-none d-lg-block col-lg-2 toc-container" id="toc-ctn">
        <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div id="tocbot"></div>
</div>

      </div>
    
  </div>
</div>

<!-- Custom -->


    
  </main>

  
    <a id="scroll-top-button" href="#" role="button">
      <i class="iconfont icon-arrowup" aria-hidden="true"></i>
    </a>
  

  
    <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v"
                 for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>
  

  

  <footer class="text-center mt-5 py-3">
  <div class="footer-content">
     <a href="https://space.bilibili.com/39165374" target="_blank" rel="nofollow noopener"><span>LMK</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
  </div>
  
  <div class="statistics">
    
    

    
      
        <!-- 不蒜子统计PV -->
        <span id="busuanzi_container_site_pv" style="display: none">
            总访问量 
            <span id="busuanzi_value_site_pv"></span>
             次
          </span>
      
      
        <!-- 不蒜子统计UV -->
        <span id="busuanzi_container_site_uv" style="display: none">
            总访客数 
            <span id="busuanzi_value_site_uv"></span>
             人
          </span>
      
    
  </div>


  

  
</footer>

<!-- SCRIPTS -->
<script  src="https://cdn.staticfile.org/jquery/3.4.1/jquery.min.js" ></script>
<script  src="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/js/bootstrap.min.js" ></script>
<script  src="/js/debouncer.js" ></script>
<script  src="/js/main.js" ></script>

<!-- Plugins -->


  
    <script  src="/js/lazyload.js" ></script>
  



  



  <script defer src="https://cdn.staticfile.org/clipboard.js/2.0.6/clipboard.min.js" ></script>
  <script  src="/js/clipboard-use.js" ></script>



  <script defer src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" ></script>





  <script  src="https://cdn.staticfile.org/tocbot/4.11.1/tocbot.min.js" ></script>
  <script>
    $(document).ready(function () {
      var boardCtn = $('#board-ctn');
      var boardTop = boardCtn.offset().top;

      tocbot.init({
        tocSelector: '#tocbot',
        contentSelector: '#post-body',
        headingSelector: 'h1,h2,h3,h4,h5,h6',
        linkClass: 'tocbot-link',
        activeLinkClass: 'tocbot-active-link',
        listClass: 'tocbot-list',
        isCollapsedClass: 'tocbot-is-collapsed',
        collapsibleClass: 'tocbot-is-collapsible',
        collapseDepth: 0,
        scrollSmooth: true,
        headingsOffset: -boardTop
      });
      if ($('.toc-list-item').length > 0) {
        $('#toc').css('visibility', 'visible');
      }
    });
  </script>



  <script  src="https://cdn.staticfile.org/typed.js/2.0.11/typed.min.js" ></script>
  <script>
    var typed = new Typed('#subtitle', {
      strings: [
        '  ',
        "docker原生网络&nbsp;",
      ],
      cursorChar: "_",
      typeSpeed: 70,
      loop: false,
    });
    typed.stop();
    $(document).ready(function () {
      $(".typed-cursor").addClass("h2");
      typed.start();
    });
  </script>



  <script  src="https://cdn.staticfile.org/anchor-js/4.2.2/anchor.min.js" ></script>
  <script>
    anchors.options = {
      placement: "right",
      visible: "hover",
      
    };
    var el = "h1,h2,h3,h4,h5,h6".split(",");
    var res = [];
    for (item of el) {
      res.push(".markdown-body > " + item)
    }
    anchors.add(res.join(", "))
  </script>



  <script  src="/js/local-search.js" ></script>
  <script>
    var path = "/local-search.xml";
    var inputArea = document.querySelector("#local-search-input");
    inputArea.onclick = function () {
      searchFunc(path, 'local-search-input', 'local-search-result');
      this.onclick = null
    }
  </script>



  <script  src="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.js" ></script>
  <link  rel="stylesheet" href="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.css" />

  <script>
    $('#post img:not(.no-zoom img, img[no-zoom]), img[zoom]').each(
      function () {
        var element = document.createElement('a');
        $(element).attr('data-fancybox', 'images');
        $(element).attr('href', $(this).attr('src'));
        $(this).wrap(element);
      }
    );
  </script>















</body>
</html>
